<?php
define('IN_PHPBB', true);
// Specify the path to you phpBB3 installation directory.
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin(false);
$auth->acl($user->data);

$user->setup();

if (isset($_POST ['message']) and isset($config['molten_chat_installed']) and !empty($config['molten_chat_enable']) and $auth->acl_get('u_molten_chat_user_send'))
{
	$color = false;
	$length = strlen ($user->data['user_colour']);

	if ($length > 0)
	{
		if ($length == 6)
		{
			$color = array(
				'red' => hexdec($user->data['user_colour'][0].$user->data['user_colour'][1]),
				'green' => hexdec($user->data['user_colour'][2].$user->data['user_colour'][3]),
				'blue' => hexdec($user->data['user_colour'][4].$user->data['user_colour'][5])
			);
		}
		elseif ($length == 3)
		{
			$color = array(
				'red' => hexdec($user->data['user_colour'][0].$user->data['user_colour'][0]),
				'green' => hexdec($user->data['user_colour'][1].$user->data['user_colour'][1]),
				'blue' => hexdec($user->data['user_colour'][2].$user->data['user_colour'][2])
			);
		}
	}

	// Only registered users are handled server-side.
	if ($user->data['is_registered'])
	{
		// Join the user to the room.
		molten_chat_server::join($user->data['username'], false, $color);

		// Update user's time.
		molten_chat_server::update($user->data['username'], false, $color);
	}

	// Send the message.
	molten_chat_server::send($_POST['message'], $user->data['username']);
}
?>